<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<link rel='stylesheet' type='text/css' href='${initParam.root }/css/mentoring.css' />
<c:set value="${sessionScope.mvo }" var="mvo"></c:set>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
	$(function(){
		
			showMentorList(${requestScope.mentoringMap.mentorList });
			showMenteeList(${requestScope.mentoringMap.menteeList });
			
		
		$(".noteView").children("td:nth-child(-n+3)").click(function(){
 			 location.href="${initParam.root}/mentoring/getNoteList.do?uid="+
			 	$(this).parents("tr").children("td:first-child").text(); 
		});
		$(".byeBtn").click(function(){
			if(confirm("멘토관계를 끊으시겠습니까? 확인을 누르시면 포인트가 차감되며 멘토관계가끊어집니다.")){
				location.href="${initParam.root}/mentoring/breakMentorRelationship.do?mentor.id="+
					$(this).parents("tr").children("td:first-child").text();
			}
		});
		$("#mentorBody").on("click",".byeMentorBtn",function(){
			if(confirm("멘토관계를 끊으시겠습니까? 확인을 누르시면 포인트가 차감되며 멘토관계가끊어집니다.")){
				$.ajax({
					url:"${initParam.root}/mentoring/breakMentorRelationship.do",
					data: "mentor.id="+$(this).parents("tr").children("td:first-child").text(),
					dataType: "json",
					success:function(data){
						showMentorList(data);
					}
					
				});
				
			}
		});
		$("#menteeBody").on("click",".byeMenteeBtn",function(){
			if(confirm("멘토관계를 끊으시겠습니까? 확인을 누르시면 포인트가 차감되며 멘토관계가끊어집니다.")){
				$.ajax({
					url:"${initParam.root}/mentoring/breakMenteeRelationship.do",
					data: "mentee.id="+$(this).parents("tr").children("td:first-child").text(),
					dataType: "json",
					success:function(data){
						showMenteeList(data);
					}
					
				});
				
			}
		});
	});
	
	function showMenteeList(data){
		
		var str="";
		$.each(data, function(i,a){
			str+="<tr class='noteView'><td><b>";
			str+=a.MENTEE_ID+"</b></td>";
			str+="<td>"+a.LEVEL_NO+"</td>";
			if(a.NEWNOTE=="0")
				str+="<td>"+a.NEWNOTE;
			else
				str+="<td  class='notRead'>"+a.NEWNOTE;
			str+="</td>";
			str+="<td><a href='#' class='byeMenteeBtn'>break</a></td></tr>";
		
		});
		$("#menteeBody").html(str);
	}
	function showMentorList(data){
		var str="";
		$.each(data, function(i,a){
			str+="<tr class='noteView'><td><b>";
			str+=a.MENTO_ID+"</b></td>";
			str+="<td>"+a.LEVEL_NO+"</td>";
			if(a.NEWNOTE=="0")
				str+="<td>"+a.NEWNOTE;
			else
				str+="<td  class='notRead'>"+a.NEWNOTE;
			str+="</td>";
		//	str+="<td><input type='button' value='멘토끊기' class='byeMentorBtn'></td></tr>";
			str+="<td><a href='#' class='byeMentorBtn'>break</a></td></tr>";		
		});
		$("#mentorBody").html(str);
	}

</script>

<div id="mymentoring">
<div id="myMentor">
<h1>MY MENTOR</h1>
<table cellpadding="3" width="100%" id="mentorTable" >
	<thead>
	<tr>
		<th>ID</th><th>LEVEL</th><th>NEW</th><th>BREAK</th>
	</tr>
	</thead>
	<tbody id="mentorBody">

	</tbody>
</table>
</div>
<div id="myMentee">
<h1>MY MENTEE</h1>
<table cellpadding="3" width="100%" id="menteeTable">
	<thead>
	<tr>
		<th>ID</th><th>LEVEL</th><th>NEW</th><th>BREAK</th>
	</tr>
	</thead>
	<tbody id="menteeBody">
	</tbody>

</table>
</div>
</div>
